//BZOJ 1500
#include <bits/stdc++.h>

using namespace std;

const int maxn=500005;
const int inf=maxn*1000+5;
struct node{
    node *ch[2];
    bool laz,rev;
    int siz,sum;
    int mx,lx,rx;
    int val;
    node *fa;
};

node pool[maxn];node *sta[maxn];
node *null,*rt;
int phead,shead;

inline node* alloc(node *fa,const int &val){
    node *ans;
    if(shead) ans=sta[--shead];
    else ans=pool+(phead++);
    ans->ch[0]=ans->ch[1]=null;
    ans->laz=ans->rev=0;
    ans->val=ans->sum=ans->mx=val;
    ans->siz=1;
    if(val>=0) ans->lx=ans->rx=val;
    else ans->lx=ans->rx=0;
    ans->fa=fa;
    return ans;
}
void recy(node* &nd){
    if(nd->ch[0]!=null) recy(nd->ch[0]);
    if(nd->ch[1]!=null) recy(nd->ch[1]);
    sta[shead++]=nd;
    nd=null;
}

inline void applyTag(node *nd,const int &val){
    nd->laz=1;nd->val=nd->mx=val;
    nd->sum=nd->val*nd->siz;
    if(nd->val>=0) nd->lx=nd->rx=nd->mx=nd->sum;
    else nd->lx=nd->rx=0;
}
inline void applyRev(node *nd){
    nd->rev^=1;
    swap(nd->ch[0],nd->ch[1]);
    swap(nd->lx,nd->rx);
}
inline void pushdown(node *nd){
    if(nd->laz){
        nd->rev=nd->laz=0;
        if(nd->ch[0]!=null) applyTag(nd->ch[0],nd->val);
        if(nd->ch[1]!=null) applyTag(nd->ch[1],nd->val);
    }else if(nd->rev){
        nd->rev=0;
        if(nd->ch[0]!=null) applyRev(nd->ch[0]);
        if(nd->ch[1]!=null) applyRev(nd->ch[1]);
    }
}
inline void update(node *nd){
    //assert(nd->lx>=0);assert(nd->rx>=0);
    if(nd->laz||nd->rev) pushdown(nd);
    nd->sum=nd->ch[0]->sum+nd->ch[1]->sum+nd->val;
    nd->siz=nd->ch[0]->siz+nd->ch[1]->siz+1;
    nd->mx=max(max(nd->ch[0]->mx,nd->ch[1]->mx),nd->ch[0]->rx+nd->ch[1]->lx+nd->val);
    nd->lx=max(nd->ch[0]->lx,nd->ch[0]->sum+nd->val+nd->ch[1]->lx);
    nd->rx=max(nd->ch[1]->rx,nd->ch[1]->sum+nd->val+nd->ch[0]->rx);
}

void rot(node *nd,node* &rt){
    /*assert(nd!=null);
    assert(rt!=null);
    assert(nd!=rt);*/
    node *f,*g;
    f=nd->fa;g=f->fa;
    int x,y;
    x=(nd==f->ch[1]);y=(f==g->ch[1]);
    f->ch[x]=nd->ch[x^1];if(nd->ch[x^1]!=null) nd->ch[x^1]->fa=f;
    nd->ch[x^1]=f;f->fa=nd;
    if(rt==f) rt=nd;
    if(g!=null) g->ch[y]=nd;
    nd->fa=g;
    update(f);update(nd);
}
void splay(node *nd,node* &rt){
    while(nd!=rt){
        node *f,*g;
        f=nd->fa;g=f->fa;
        int x,y;
        x=(nd==f->ch[1]);y=(f==g->ch[1]);
        if(f!=rt){
            if(x==y) rot(f,rt);
            else rot(nd,rt);
        }
        rot(nd,rt);
    }
}
node *rnk(node* rt,int rk){
    node *ans;
    pushdown(rt);
    if(rk<=rt->ch[0]->siz) ans=rnk(rt->ch[0],rk);
    else if(rk==rt->ch[0]->siz+1) ans=rt;
    else ans=rnk(rt->ch[1],rk-rt->ch[0]->siz-1);
    update(rt);
    return ans;
}
void split(node *bg,node *ed){
    //assert(bg!=null);assert(ed!=null);
    splay(bg,rt);splay(ed,bg->ch[1]);
}

void build(int *arr,const int &n,node* &rt,node *fa=null){
    int mid=n>>1;
    rt=alloc(fa,arr[mid]);
    if(mid) build(arr,mid,rt->ch[0],rt);
    if(mid+1<n) build(arr+mid+1,n-mid-1,rt->ch[1],rt);
    update(rt);
}
void ins(int *arr,const int &n,const int &pos){
    split(rnk(rt,pos),rnk(rt,pos+1));
    build(arr,n,rt->ch[1]->ch[0],rt->ch[1]);
    update(rt->ch[1]);update(rt);
}

inline int read(){
    char c;int r;bool f=0;
    for(c=getchar();c>'9'||c<'0';c=getchar()) if(c=='-') f=1;
    for(r=0;c<='9'&&c>='0';c=getchar()) r=r*10+c-'0';
    if(f) return -r;
    else return r;
}

inline void cut(){
    int pos,tot;
    pos=read();tot=read();
    split(rnk(rt,pos),rnk(rt,pos+tot+1));
    //assert(rt->ch[1]->ch[0]->siz==tot);
}

int a[maxn];
char str[20];

int main(){
    null=new node;
    null->ch[0]=null->ch[1]=null->fa=null;
    null->sum=null->siz=null->laz=null->rev=0;
    null->mx=-inf;
    null->lx=null->rx=null->val=0;

    int n,m;
    n=read();m=read();
    for(int i=1;i<=n;i++) a[i]=read();
    a[0]=a[n+1]=-inf;n=n+2;
    build(a,n,rt,null);
    while(m--){
        scanf("%s",str);
        int pos,tot,val;
        if(!strcmp(str,"INSERT")){
            pos=read();tot=read();
            for(int i=0;i<tot;i++) a[i]=read();
            ins(a,tot,pos+1);
        }else if(!strcmp(str,"DELETE")){
            cut();
            recy(rt->ch[1]->ch[0]);
            update(rt->ch[1]);update(rt);
        }else if(!strcmp(str,"MAKE-SAME")){
            cut();val=read();
            applyTag(rt->ch[1]->ch[0],val);
            update(rt->ch[1]);update(rt);
        }else if(!strcmp(str,"REVERSE")){
            cut();
            applyRev(rt->ch[1]->ch[0]);
            update(rt->ch[1]);update(rt);
        }else if(!strcmp(str,"GET-SUM")){
            cut();
            printf("%d\n",rt->ch[1]->ch[0]->sum);
        }else if(!strcmp(str,"MAX-SUM")){
            printf("%d\n",rt->mx);
        }else assert(false);
    }

    return 0;
}
